﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using Com.Gcssloop.Widget;
using FFImageLoading;
using FFImageLoading.Views;
using mb;
using mb.Droid;
using GridLayout = Android.Support.V7.Widget.GridLayout;

namespace libmp
{
    class HomeMovieView : ExMovieList
    {
        public static MyFragment CreateFragment()
        {
            return new MyFragment()
            {
                Title = "视频",
                    MyOnCreateView = (f, container) =>
                    {
                        return new HomeMovieView(f).CreateView();
                    },
            };
        }

        MyFragment fragment;
        LinearLayout rootLayout;
        RCRelativeLayout adLayout;
        ViewPager adPager;

        public HomeMovieView(MyFragment f)
        {
            this.fragment = f;
        }

        public View CreateView()
        {
            if (rootLayout != null) return rootLayout;

            rootLayout = new LinearLayout(activity);
            rootLayout.FillParent();

            User.me.OnChanged += (user) =>
            {
                logger.Log("user changed...");
            };

            CreateADView();
            CreateList();
            return rootLayout;
        }

        void CreateADView()
        {

            int margin = 20;
            int height = Util.dpToPx(160);
            int vheight = height - margin * 2;
            insertItems.Add(new InsertItem()
            {
                insertBefore = 0,
                    height = height,
                    view = new AdImageView(0, 10).CreateView().SetLayoutParam(new LinearLayout.LayoutParams(-1, vheight) { TopMargin = margin, LeftMargin = margin, RightMargin = margin, })
            });

            insertItems.Add(new InsertItem()
            {
                insertBefore = 6,
                    height = height,
                    view = new AdImageView(2, 3).CreateView().SetLayoutParam(new LinearLayout.LayoutParams(-1, vheight) { TopMargin = margin, LeftMargin = margin, RightMargin = margin, })
            });
        }

        void CreateList()
        {
            dataSource = DataStore.store.GetRecommendVideoList();
            Setup();
            Reload();

            GetListView().FillParent();
            rootLayout.AddView(GetListView());
        }

    };

}